#include <stdio.h>


/*
 * 2010.12.28 20:39
 * 无类型指针在结构体里怎么强制类型转换
 */


typedef struct A {
        int a;
        char b;
}A;

A tmp = {10, '0'};

void print(void)
{
        printf("tmp.a = %d tmp.b = %c\n", tmp.a, tmp.b);	// tmp.a = 10 tmp.b = 0

        printf("&tmp = %p &tmp.a = %p &tmp.b = %p\n", 
                        (unsigned long)(void *)&tmp, 
                        (unsigned long)(void *)&tmp.a,
                        (unsigned long)(void *)&tmp.b);	// &tmp = 0x804995c &tmp.a = 0x804995c &tmp.b = 0x8049960

        printf("sizeof tmp = %d sizeof tmp.a = %d sizeof tmp.b = %d\n", 
                        sizeof(A),
                        sizeof(int),
                        sizeof(char));	// sizeof tmp = 8 sizeof tmp.a = 4 sizeof tmp.b = 1;  A=8字节为为了结构体对齐
}

void priBit(int t)
{
        int i = 32;

        printf("t = %d\n", t);
        for (; i > 0; i--)
        {
                printf("%d", (t >> i) & 0x0001);
        }
        printf("\n");
}

int _main()
{
        int *p = NULL;

        print();
        p = (int *)&tmp;
        priBit(*p);
        priBit(*(p + 1));	// 指向下一个字段;  48 = '0'
}

struct stu
{
        char name[20];
        int num;
};

int main()
{
        void *p = NULL;
        struct stu a={"li main",5};
        p=&a;
        printf(" %s %d  \n",( (struct stu *) p )->name,( (struct stu *) p )->num);	// li main 5 

		_main();

		return 0;
}
 
